/// <reference path="../game/fourkill.util.js" />
/// <reference path="../game/fourkill.sprite.singletons.js" />
/// <reference path="../painters/fourkill.painter.singletons.js" />

var FlyingBirdObject = GameObject.extend({
    initialize: function initialize() {
        GameObject.initialize.call(this);

        this.BOUNDRY_SIZE = 20000;
        this.z = util.random(30, 200);
        this.speed = 1 + util.random();
        this.boundaries = null;
        this.moveAwayCounter = 0;
        this.sprite = SpriteSheets.Bird;
    },
    tick: function tick() {

        if (this.boundaries == null) {
            this.boundaries = Rectangle.newInstance(this.x - this.BOUNDRY_SIZE, this.y - this.BOUNDRY_SIZE, this.BOUNDRY_SIZE * 2, this.BOUNDRY_SIZE * 2);
            this.moveAwayCounter = 0;
        }
        else {
            /*if (!this.boundaries.contains(this.x, this.y)) {
                if (this.moveAwayCounter == 0) {
                    this.turn(util.radians(util.random(150, 210)));
                    this.moveAwayCounter = util.random(3, 6);
                }
            }
            else {
                this.moveAwayCounter = 0;
            }*/
            this.moveAwayCounter = 0;
        }
        if (this.moveAwayCounter == 0) {
            var r = util.random(50);
            if (r < 10) {
                if (this.z > 200) this.z += util.random(-2, 0);
                else if (this.z < 20) this.z += util.random(0, 2);
                else this.z += util.random(-1, 1);
            }
            if (r == 25) this.speed = 1 + util.random();
            if (r == 45) this.turn(util.radians(util.random(-30, 30)));
            else this.turn(util.radians(util.random(-2, 2)));
        }
        else {
            this.moveAwayCounter--;
        }
        this.move(this.speed);
    },
    getPainter: function getPainter() { return Painters.SpriteSheetPainter; }
});
